﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using WeighClient.Model;

namespace WeighClient.Windows
{
    /// <summary>
    /// PurchaseInfoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PurchaseInfoWindow : Window
    {
        Bill billModel;
        string labelMsg = "";
        private DispatcherTimer timer;
        private String TextProperty1 = String.Empty;
        public PurchaseInfoWindow(Bill bill)
        {
            InitializeComponent();
            InitializeComponent();
            billModel = bill;
            this.DataContext = billModel;
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timeCycle);
            timer.Start();
        }
        public void timeCycle(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                Application.Current.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        TextProperty1 = DateTime.Now.ToString();
                        this.labelTime.Text = TextProperty1;
                    }));
            }).Start();
        }

        public void UpdateBill(Bill bill)
        {
            billModel = bill;
            this.DataContext = billModel;

        }
        public void LabelMsg(string msg)
        {
            this.labelMsg = msg;
            errorLabel.Content = labelMsg;

        }
    }
}
